import component from './shareMark.vue'
import Vue from 'vue'
import { getEvn } from '@/utils/h5/handleEvn'

const Constructor = Vue.extend(component)
const instance = new Constructor({
  el: document.createElement('div')
})
export default {
  init(options) {
    instance.handelShare(options)
  },
  show(options, cb) {
    this.hide()
    instance.handelShare(options).then(() => {
      const el = document.body
      const env = getEvn()

      el.appendChild(instance.$el)
      if (env === 'wx') {
        instance.show = true
      }
      cb && cb()
    })
  },

  hide() {
    const el = instance.$el
    el.parentNode && el.parentNode.removeChild(el)
    instance.show = false
  }
}
